#include <iostream>
#define num 3
void test0();
void test_input();
void test_get_lenth();
using namespace std;
int main_test_get()
{
    test_get_lenth();
    // test_input();
    return 0;
}

void test_get_lenth()
{

    char ch2[10];
    cout << "please input a string:" << endl;
    cin.get(ch2, 6);
    char ch1;
    cin.get(ch1);
    cout << "ch2=" << ch2 << endl;
    cout << "ch1=[" << ch1 << "] code=" << (int)ch1 << endl;
    /*
    这是一种截断的效果，也就是说最后cin.get中生成的字符串长度是根据后面设置的值来定的
    如果比较小，那么缓冲区中还是有值的，其值是下一个未读取出的字符
    please input a string:
    zifuchuan
    ch2=zifuc
    ch1=[h] code=104

    //如果数量不够个，则全部读出，同时enter还是在的，这时使用cin.get(ch1)还是可以获取到的
    please input a string:
    zifu
    ch2=zifu
    ch1=[
    ] code=10
    */
}

void test_input() 
{
    char ch1, ch2;
    cout << "please input two charactors:" << endl;
    cin.get(ch1);
    cin.get(ch2);
    cout << "ch1=[" << ch1 << "] code=" << (int)ch1 << endl;
    cout << "ch2=[" << ch2 << "] code=" << (int)ch2 << endl;
    //可以看到空格被作为正常的字符处理，enter也被存入缓存区，同时还能被get获取到
    /*
    please input two charactors:
    a b
    ch1=[a] code=97
    ch2=[ ] code=32
    
    please input two charactors:
    a
    ch1=[a] code=97
    ch2=[
    ] code=10
    */
}

void test0() {
    
    char names[10];
    char deserts[10];
    //get中可以输入空格和enter【默认情况下是以结束符作为分隔符的】，并且会将空格和enter保存进缓存区
    cout << "Please input your name:" << endl;
    cin.get(names, num);//因为还要留\0的位置，所以这里只能存num - 1个数据
    cout << "Please input your favourite food: " << endl;
    cin.get(deserts, num);
    cout << names << "'s favourite food is:" << deserts << endl;
    /*
    out:
    Please input your name:
    MM jj
    Please input your favourite food: 
    MM's favourite food is: j
    */
}
